package com.gxa.admin.recycling.controller;

import com.gxa.admin.recycling.service.AdviceService;
import com.gxa.core.recycling.common.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2021-12-03 17:02
 */
@RestController
@RequestMapping("/advice")
@Api(tags = "问题投诉")
@Transactional(rollbackFor = Throwable.class)
public class AdviceController {

    @Autowired
    AdviceService service;

    @PostMapping("/getAllAdvices")
    @ApiOperation("获得所有的问题投诉")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true,dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页记录数",required = true,dataType = "Integer",paramType = "query")
    })
    public Map getAllAdvices(Integer page,Integer size){
        List<Map<String, Object>> allAdvices = service.getAllAdvices(page, size);
        Integer allAdvicesCount = service.getAllAdvicesCount(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setMsg("查询成功");
        jsonResult.setCode("200");
        jsonResult.setData(allAdvices);
        jsonResult.put("count",allAdvicesCount);
        return jsonResult.getDataMap();
    }

    @PostMapping("/getById")
    @ApiOperation("查看建议详情")
    @ApiImplicitParam(name = "id",value = "查询建议的id",required = true,dataType = "Integer",paramType = "query")
    public Map getById(Integer id){
        Map<String, Object> byId = service.getById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(byId);
        return jsonResult.getDataMap();
    }

    @PostMapping("/deleteById")
    @ApiOperation("删除")
    @ApiImplicitParam(name = "id",value = "需要删除的id",required = true,dataType = "Integer",paramType = "query")
    public Map delete(Long id){
        Integer integer = service.deleteById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }
}
